
<?php
require('_config-rating.php'); // get the db connection info
if (isset($_GET["page"])) 
{ 
	$page  = $_GET["page"]; 
} else { 
	$page=1; 
};

if (isset($_GET["userid"])) 
{ 
	$userid  = $_GET["userid"]; 
} else { 
	$userid=123456; 
};

if (isset($_GET["gListName"])) 
{ 
	$gListName  = $_GET["gListName"]; 
} else { 
	return; 
};

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
}


//$sql = "SELECT COUNT(*) FROM games WHERE gameId IN (SELECT gameId FROM favorites WHERE personId =$userid )";
$sql = "select * from games where gameId in (SELECT gameId FROM listgamerelations l where l.listId = "; 
$sql=$sql."(select gameListId from gamelist where gameListName='$gListName' and userId=$userid))";

$rs_result = mysql_query($sql,$con); 

if ($row = mysql_fetch_array($rs_result)){
$pageInclude=1;
$total_records = $row[0]; 
$total_pages = ceil($total_records / $pageInclude); 
$outputPagination='<div class="navigation">';
$outputPagination=$outputPagination.'<div align="center" class="navigation"><ol class="wp-paginate"><li><span class="title"></span></li>';

$startPage=1;
$pageCount=2;
if ($pageCount>=$total_pages){
	$startPage=1;
	$loopCount=$total_pages;
}else if($page+$pageCount<=$total_pages){
	if ($page>1)$startPage=$page-1;
	else $startPage=1;
	$loopCount=$startPage+$pageCount;
}else if($page+$pageCount>$total_pages){
	$startPage=$total_pages-$pageCount;
	$loopCount=$startPage+$pageCount;
}
/*if($page+$pageCount<=$total_pages && $page-1>0){
	$startPage=$page-1;
}else if($page+$pageCount>$total_pages){
	$startPage=$total_pages-$pageCount;
}*/

if(($page-1)>0){
	$outputPagination=$outputPagination.'<li><a class="next" href="myProfil.php?page='.($page-1).'&gListName='.$gListName.'&user_pic='.$pic.'&userid='.$userid.'">«</a></li>';
}
for ($i=$startPage; $i<=$loopCount; $i++) { 
	if($page==$i){
		$outputPagination=$outputPagination.'<li><span class="page current">'.$i.'</span></li>';
	}else{
		$outputPagination=$outputPagination.'<li><a class="page" title='.$i.' href="myProfil.php?page='.$i.'&gListName='.$gListName.'&user_pic='.$pic.'&userid='.$userid.'">'.$i.'</a></li>';
	}
    //echo "<a href='pagination.php?page=".$i."'>".$i."</a> "; 
};
if(($page+1)<=$total_pages){
	$outputPagination=$outputPagination.'<li><a class="next" href="myProfil.php?page='.($page+1).'&gListName='.$gListName.'&user_pic='.$pic.'&userid='.$userid.'">»</a></li>';
}

$outputPagination=$outputPagination.'</ol></div></div>';
}

echo $outputPagination;

mysql_close();
?>
